﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Teigha.Core
{
	public class OdBrFace : OdBrEntity
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdBrFace(IntPtr cPtr, bool cMemoryOwn) : base(GlobalsPINVOKE.OdBrFace_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdBrFace obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdBrFace()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							GlobalsPINVOKE.delete_OdBrFace(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public OdBrErrorStatus getSurfaceAsNurb(OdGeNurbSurface nurb)
		{
			OdBrErrorStatus result = (OdBrErrorStatus)GlobalsPINVOKE.OdBrFace_getSurfaceAsNurb(this.swigCPtr, OdGeNurbSurface.getCPtr(nurb));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdGeSurface getSurface()
		{
			IntPtr intPtr = GlobalsPINVOKE.OdBrFace_getSurface(this.swigCPtr);
			OdGeSurface result = (intPtr == IntPtr.Zero) ? null : new OdGeSurface(intPtr, false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdBrErrorStatus getSurfaceType(OdGe.EntityId surfaceType)
		{
			OdBrErrorStatus result = (OdBrErrorStatus)GlobalsPINVOKE.OdBrFace_getSurfaceType(this.swigCPtr, surfaceType);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool getOrientToSurface()
		{
			bool result = GlobalsPINVOKE.OdBrFace_getOrientToSurface(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool getColor(OdCmEntityColor color)
		{
			bool result = GlobalsPINVOKE.OdBrFace_getColor(this.swigCPtr, OdCmEntityColor.getCPtr(color));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool getMaterialID(out ulong id)
		{
			bool result = GlobalsPINVOKE.OdBrFace_getMaterialID(this.swigCPtr, out id);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool getMaterialString(ref string strMatName)
		{
			IntPtr intPtr = Marshal.StringToCoTaskMemUni(strMatName);
			IntPtr value = intPtr;
			bool result;
			try
			{
				bool flag = GlobalsPINVOKE.OdBrFace_getMaterialString(this.swigCPtr, ref intPtr);
				if (GlobalsPINVOKE.SWIGPendingException.Pending)
				{
					throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
				}
				result = flag;
			}
			finally
			{
				if (intPtr != value)
				{
					strMatName = Marshal.PtrToStringUni(intPtr);
				}
			}
			return result;
		}

		public bool getMaterialMapper(OdGeMatrix3d mx, OdBrFace.Projection projection, OdBrFace.Tiling tiling, OdBrFace.AutoTransform autoTransform)
		{
			bool result = GlobalsPINVOKE.OdBrFace_getMaterialMapper(this.swigCPtr, OdGeMatrix3d.getCPtr(mx), projection, tiling, autoTransform);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdBrFace() : this(GlobalsPINVOKE.new_OdBrFace(), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		public enum Projection
		{
			kInheritProjection,
			kPlanar,
			kBox,
			kCylinder,
			kSphere
		}

		public enum Tiling
		{
			kInheritTiling,
			kTile,
			kCrop,
			kClamp,
			kMirror
		}

		public enum AutoTransform
		{
			kInheritAutoTransform,
			kNone,
			kObject,
			kModel = 4
		}
	}
}
